{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第九周实践"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 堆叠柱状图（纵向）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1828\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1828\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      if (url in hashes) {\n",
       "        element.crossOrigin = \"anonymous\";\n",
       "        element.integrity = \"sha384-\" + hashes[url];\n",
       "      }\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1828\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1828\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      if (url in hashes) {\n        element.crossOrigin = \"anonymous\";\n        element.integrity = \"sha384-\" + hashes[url];\n      }\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1828\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "from bokeh.plotting import output_notebook,figure,show\n",
    "import pandas as pd\n",
    "from bokeh.models import ColumnDataSource,FactorRange\n",
    "from bokeh.palettes import Spectral6,Blues6,Spectral3,Spectral5\n",
    "from bokeh.transform import factor_cmap\n",
    "from bokeh.core.properties import value\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "#数据准备\n",
    "fruits=['apples','pears','nectarines','plums','grapes','strawberries']\n",
    "years=[\"2015\",\"2016\",\"2017\"]\n",
    "colors = Spectral3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "data={\n",
    "    'fruits':['apples','pears','nectarines','plums','grapes','strawberries'],\n",
    "    '2015':[2,1,4,3,2,4],\n",
    "    '2016':[5,3,4,2,4,6],\n",
    "    '2017':[3,2,4,4,5,3],\n",
    "    'years':[\"2015\",\"2016\",\"2017\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('2015', 6), ('2016', 6), ('2017', 6), ('fruits', 6), ('years', 3)\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"5e5e2f48-0ea8-49ac-af0e-44072aed635a\" data-root-id=\"2694\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"63d12145-52c2-428d-a6ec-e3b1b5571092\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2705\"}],\"center\":[{\"id\":\"2707\"},{\"id\":\"2711\"},{\"id\":\"2751\"}],\"left\":[{\"id\":\"2708\"}],\"plot_height\":300,\"renderers\":[{\"id\":\"2741\"},{\"id\":\"2756\"},{\"id\":\"2770\"},{\"id\":\"2784\"},{\"id\":\"2798\"}],\"title\":{\"id\":\"2695\"},\"toolbar\":{\"id\":\"2720\"},\"x_range\":{\"id\":\"2697\"},\"x_scale\":{\"id\":\"2701\"},\"y_range\":{\"id\":\"2699\"},\"y_scale\":{\"id\":\"2703\"}},\"id\":\"2694\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2732\"}},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"2733\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2768\",\"type\":\"VBar\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"@years\",\"@fruits:@$name\"]]},\"id\":\"2719\",\"type\":\"HoverTool\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2730\"}},\"fill_color\":{\"value\":\"#abdda4\"},\"line_color\":{\"value\":\"#abdda4\"},\"top\":{\"expr\":{\"id\":\"2731\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2754\",\"type\":\"VBar\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e09\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2770\"}]},\"id\":\"2780\",\"type\":\"LegendItem\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2728\"}},\"fill_color\":{\"value\":\"#2b83ba\"},\"line_color\":{\"value\":\"#2b83ba\"},\"top\":{\"expr\":{\"id\":\"2729\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2739\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\"]},\"id\":\"2729\",\"type\":\"Stack\"},{\"attributes\":{\"factors\":[\"apples\",\"pears\",\"nectarines\",\"plums\",\"grapes\",\"strawberries\"]},\"id\":\"2697\",\"type\":\"FactorRange\"},{\"attributes\":{\"axis\":{\"id\":\"2705\"},\"ticker\":null},\"id\":\"2707\",\"type\":\"Grid\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2736\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#d7191c\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#d7191c\"},\"top\":{\"expr\":{\"id\":\"2737\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2797\",\"type\":\"VBar\"},{\"attributes\":{\"text\":\"\\u6c34\\u679c\\u6bcf\\u5e74\\u6570\\u91cf\"},\"id\":\"2695\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2748\",\"type\":\"Selection\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"\\u7b2c\\u56db\\u5b63\\u5ea6\",\"\\u7b2c\\u4e94\\u5b63\\u5ea6\"]},\"id\":\"2737\",\"type\":\"Stack\"},{\"attributes\":{\"fields\":[]},\"id\":\"2728\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2712\",\"type\":\"PanTool\"},{\"attributes\":{\"axis\":{\"id\":\"2708\"},\"dimension\":1,\"ticker\":null},\"id\":\"2711\",\"type\":\"Grid\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e94\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2798\"}]},\"id\":\"2808\",\"type\":\"LegendItem\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\"]},\"id\":\"2733\",\"type\":\"Stack\"},{\"attributes\":{\"formatter\":{\"id\":\"2744\"},\"ticker\":{\"id\":\"2709\"}},\"id\":\"2708\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2744\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"2693\"}},\"id\":\"2799\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2701\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"2709\",\"type\":\"BasicTicker\"},{\"attributes\":{\"data_source\":{\"id\":\"2693\"},\"glyph\":{\"id\":\"2754\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2755\"},\"selection_glyph\":null,\"view\":{\"id\":\"2757\"}},\"id\":\"2756\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2699\",\"type\":\"DataRange1d\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u56db\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2784\"}]},\"id\":\"2794\",\"type\":\"LegendItem\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\"]},\"id\":\"2731\",\"type\":\"Stack\"},{\"attributes\":{\"data_source\":{\"id\":\"2693\"},\"glyph\":{\"id\":\"2796\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e94\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2797\"},\"selection_glyph\":null,\"view\":{\"id\":\"2799\"}},\"id\":\"2798\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"2693\"}},\"id\":\"2771\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2749\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"formatter\":{\"id\":\"2746\"},\"ticker\":{\"id\":\"2706\"}},\"id\":\"2705\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"overlay\":{\"id\":\"2718\"}},\"id\":\"2714\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"\\u7b2c\\u56db\\u5b63\\u5ea6\"]},\"id\":\"2736\",\"type\":\"Stack\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"2712\"},{\"id\":\"2713\"},{\"id\":\"2714\"},{\"id\":\"2715\"},{\"id\":\"2716\"},{\"id\":\"2717\"},{\"id\":\"2719\"}]},\"id\":\"2720\",\"type\":\"Toolbar\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2734\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#fdae61\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#fdae61\"},\"top\":{\"expr\":{\"id\":\"2735\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2783\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2703\",\"type\":\"LinearScale\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2728\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#2b83ba\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#2b83ba\"},\"top\":{\"expr\":{\"id\":\"2729\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2740\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2716\",\"type\":\"ResetTool\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\"]},\"id\":\"2732\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2715\",\"type\":\"SaveTool\"},{\"attributes\":{\"source\":{\"id\":\"2693\"}},\"id\":\"2742\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"2693\"},\"glyph\":{\"id\":\"2768\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2769\"},\"selection_glyph\":null,\"view\":{\"id\":\"2771\"}},\"id\":\"2770\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"items\":[{\"id\":\"2752\"},{\"id\":\"2766\"},{\"id\":\"2780\"},{\"id\":\"2794\"},{\"id\":\"2808\"}]},\"id\":\"2751\",\"type\":\"Legend\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2732\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"2733\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2769\",\"type\":\"VBar\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2736\"}},\"fill_color\":{\"value\":\"#d7191c\"},\"line_color\":{\"value\":\"#d7191c\"},\"top\":{\"expr\":{\"id\":\"2737\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2796\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2713\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2730\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#abdda4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#abdda4\"},\"top\":{\"expr\":{\"id\":\"2731\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2755\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2717\",\"type\":\"HelpTool\"},{\"attributes\":{\"source\":{\"id\":\"2693\"}},\"id\":\"2785\",\"type\":\"CDSView\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"\\u7b2c\\u56db\\u5b63\\u5ea6\"]},\"id\":\"2735\",\"type\":\"Stack\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2718\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2746\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\"]},\"id\":\"2734\",\"type\":\"Stack\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e00\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2741\"}]},\"id\":\"2752\",\"type\":\"LegendItem\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2734\"}},\"fill_color\":{\"value\":\"#fdae61\"},\"line_color\":{\"value\":\"#fdae61\"},\"top\":{\"expr\":{\"id\":\"2735\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"fruits\"}},\"id\":\"2782\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"2693\"}},\"id\":\"2757\",\"type\":\"CDSView\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2756\"}]},\"id\":\"2766\",\"type\":\"LegendItem\"},{\"attributes\":{\"data_source\":{\"id\":\"2693\"},\"glyph\":{\"id\":\"2739\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2740\"},\"selection_glyph\":null,\"view\":{\"id\":\"2742\"}},\"id\":\"2741\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2706\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\"]},\"id\":\"2730\",\"type\":\"Stack\"},{\"attributes\":{\"data_source\":{\"id\":\"2693\"},\"glyph\":{\"id\":\"2782\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u56db\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2783\"},\"selection_glyph\":null,\"view\":{\"id\":\"2785\"}},\"id\":\"2784\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data\":{\"2015\":[2,1,4,3,2,4],\"2016\":[5,3,4,2,4,6],\"2017\":[3,2,4,4,5,3],\"fruits\":[\"apples\",\"pears\",\"nectarines\",\"plums\",\"grapes\",\"strawberries\"],\"years\":[\"2015\",\"2016\",\"2017\"]},\"selected\":{\"id\":\"2748\"},\"selection_policy\":{\"id\":\"2749\"}},\"id\":\"2693\",\"type\":\"ColumnDataSource\"}],\"root_ids\":[\"2694\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"63d12145-52c2-428d-a6ec-e3b1b5571092\",\"root_ids\":[\"2694\"],\"roots\":{\"2694\":\"5e5e2f48-0ea8-49ac-af0e-44072aed635a\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2694"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "source = ColumnDataSource(\n",
    "    data = data\n",
    ")\n",
    "\n",
    "TOOLTIPS = [\n",
    "    (\"@years\",\"@fruits:@$name\")\n",
    "]\n",
    "\n",
    "#画布\n",
    "p = figure(\n",
    "    x_range = fruits,\n",
    "    plot_height = 300,\n",
    "    title = \"水果每年数量\",\n",
    "#     source = source,\n",
    "    tooltips = TOOLTIPS\n",
    "\n",
    ")\n",
    "\n",
    "#画图\n",
    "p.vbar_stack(\n",
    "    years,\n",
    "    x = 'fruits',\n",
    "    width = 0.8,\n",
    "    color = colors,\n",
    "    source = source,\n",
    "    legend = [value(x) for x in years]\n",
    "\n",
    ")\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>指标</th>\n",
       "      <th>2022年第一季度</th>\n",
       "      <th>2021年第四季度</th>\n",
       "      <th>2021年第三季度</th>\n",
       "      <th>2021年第二季度</th>\n",
       "      <th>2021年第一季度</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>13360</td>\n",
       "      <td>44993</td>\n",
       "      <td>35694</td>\n",
       "      <td>23604</td>\n",
       "      <td>12636</td>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>16230</td>\n",
       "      <td>54854</td>\n",
       "      <td>43592</td>\n",
       "      <td>28897</td>\n",
       "      <td>15472</td>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>6639</td>\n",
       "      <td>22306</td>\n",
       "      <td>17619</td>\n",
       "      <td>11490</td>\n",
       "      <td>6225</td>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>20630</td>\n",
       "      <td>75002</td>\n",
       "      <td>56498</td>\n",
       "      <td>38138</td>\n",
       "      <td>19585</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>22274</td>\n",
       "      <td>81518</td>\n",
       "      <td>61243</td>\n",
       "      <td>41381</td>\n",
       "      <td>21189</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>10016</td>\n",
       "      <td>33303</td>\n",
       "      <td>26125</td>\n",
       "      <td>17383</td>\n",
       "      <td>9326</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>22663</td>\n",
       "      <td>78027</td>\n",
       "      <td>58907</td>\n",
       "      <td>40357</td>\n",
       "      <td>21548</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>23772</td>\n",
       "      <td>82429</td>\n",
       "      <td>61915</td>\n",
       "      <td>42348</td>\n",
       "      <td>22636</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>12891</td>\n",
       "      <td>38521</td>\n",
       "      <td>31985</td>\n",
       "      <td>22535</td>\n",
       "      <td>12006</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>19366</td>\n",
       "      <td>57541</td>\n",
       "      <td>44712</td>\n",
       "      <td>30998</td>\n",
       "      <td>18263</td>\n",
       "      <td>浙江省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>22784</td>\n",
       "      <td>68487</td>\n",
       "      <td>52758</td>\n",
       "      <td>36294</td>\n",
       "      <td>21600</td>\n",
       "      <td>浙江省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>12541</td>\n",
       "      <td>35247</td>\n",
       "      <td>28474</td>\n",
       "      <td>20357</td>\n",
       "      <td>11686</td>\n",
       "      <td>浙江省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>16490</td>\n",
       "      <td>47498</td>\n",
       "      <td>36227</td>\n",
       "      <td>25119</td>\n",
       "      <td>15500</td>\n",
       "      <td>江苏省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>19251</td>\n",
       "      <td>57743</td>\n",
       "      <td>44267</td>\n",
       "      <td>30491</td>\n",
       "      <td>18194</td>\n",
       "      <td>江苏省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>10952</td>\n",
       "      <td>26791</td>\n",
       "      <td>20267</td>\n",
       "      <td>14455</td>\n",
       "      <td>10215</td>\n",
       "      <td>江苏省</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   指标  2022年第一季度  2021年第四季度  2021年第三季度  2021年第二季度  2021年第一季度  \\\n",
       "0     居民人均可支配收入累计值(元)      13360      44993      35694      23604      12636   \n",
       "1   城镇居民人均可支配收入累计值(元)      16230      54854      43592      28897      15472   \n",
       "2   农村居民人均可支配收入累计值(元)       6639      22306      17619      11490       6225   \n",
       "3     居民人均可支配收入累计值(元)      20630      75002      56498      38138      19585   \n",
       "4   城镇居民人均可支配收入累计值(元)      22274      81518      61243      41381      21189   \n",
       "5   农村居民人均可支配收入累计值(元)      10016      33303      26125      17383       9326   \n",
       "6     居民人均可支配收入累计值(元)      22663      78027      58907      40357      21548   \n",
       "7   城镇居民人均可支配收入累计值(元)      23772      82429      61915      42348      22636   \n",
       "8   农村居民人均可支配收入累计值(元)      12891      38521      31985      22535      12006   \n",
       "9     居民人均可支配收入累计值(元)      19366      57541      44712      30998      18263   \n",
       "10  城镇居民人均可支配收入累计值(元)      22784      68487      52758      36294      21600   \n",
       "11  农村居民人均可支配收入累计值(元)      12541      35247      28474      20357      11686   \n",
       "12    居民人均可支配收入累计值(元)      16490      47498      36227      25119      15500   \n",
       "13  城镇居民人均可支配收入累计值(元)      19251      57743      44267      30491      18194   \n",
       "14  农村居民人均可支配收入累计值(元)      10952      26791      20267      14455      10215   \n",
       "\n",
       "     地区  \n",
       "0   广东省  \n",
       "1   广东省  \n",
       "2   广东省  \n",
       "3    北京  \n",
       "4    北京  \n",
       "5    北京  \n",
       "6   上海市  \n",
       "7   上海市  \n",
       "8   上海市  \n",
       "9   浙江省  \n",
       "10  浙江省  \n",
       "11  浙江省  \n",
       "12  江苏省  \n",
       "13  江苏省  \n",
       "14  江苏省  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "haha = pd.read_csv('居民人均可支配收入.csv',sep=\",\",encoding=\"utf-8\")\n",
    "haha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>指标</th>\n",
       "      <th>2022年第一季度</th>\n",
       "      <th>2021年第四季度</th>\n",
       "      <th>2021年第三季度</th>\n",
       "      <th>2021年第二季度</th>\n",
       "      <th>2021年第一季度</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>13360</td>\n",
       "      <td>44993</td>\n",
       "      <td>35694</td>\n",
       "      <td>23604</td>\n",
       "      <td>12636</td>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>20630</td>\n",
       "      <td>75002</td>\n",
       "      <td>56498</td>\n",
       "      <td>38138</td>\n",
       "      <td>19585</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>22663</td>\n",
       "      <td>78027</td>\n",
       "      <td>58907</td>\n",
       "      <td>40357</td>\n",
       "      <td>21548</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>19366</td>\n",
       "      <td>57541</td>\n",
       "      <td>44712</td>\n",
       "      <td>30998</td>\n",
       "      <td>18263</td>\n",
       "      <td>浙江省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>16490</td>\n",
       "      <td>47498</td>\n",
       "      <td>36227</td>\n",
       "      <td>25119</td>\n",
       "      <td>15500</td>\n",
       "      <td>江苏省</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 指标  2022年第一季度  2021年第四季度  2021年第三季度  2021年第二季度  2021年第一季度  \\\n",
       "0   居民人均可支配收入累计值(元)      13360      44993      35694      23604      12636   \n",
       "3   居民人均可支配收入累计值(元)      20630      75002      56498      38138      19585   \n",
       "6   居民人均可支配收入累计值(元)      22663      78027      58907      40357      21548   \n",
       "9   居民人均可支配收入累计值(元)      19366      57541      44712      30998      18263   \n",
       "12  居民人均可支配收入累计值(元)      16490      47498      36227      25119      15500   \n",
       "\n",
       "     地区  \n",
       "0   广东省  \n",
       "3    北京  \n",
       "6   上海市  \n",
       "9   浙江省  \n",
       "12  江苏省  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "居民人均可支配收入累计值 = haha.query('指标==\"居民人均可支配收入累计值(元)\"')\n",
    "居民人均可支配收入累计值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广东省', '北京', '上海市', '浙江省', '江苏省']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "region = 居民人均可支配收入累计值['地区']\n",
    "region = list(region)\n",
    "region"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[12636, 19585, 21548, 18263, 15500]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "第一季度 = 居民人均可支配收入累计值['2021年第一季度']\n",
    "第一季度 = list(第一季度)\n",
    "第一季度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[23604, 38138, 40357, 30998, 25119]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "第二季度 = 居民人均可支配收入累计值['2021年第二季度']\n",
    "第二季度 = list(第二季度)\n",
    "第二季度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[35694, 56498, 58907, 44712, 36227]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "第三季度 = 居民人均可支配收入累计值['2021年第三季度']\n",
    "第三季度 = list(第三季度)\n",
    "第三季度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[44993, 75002, 78027, 57541, 47498]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "第四季度 = 居民人均可支配收入累计值['2021年第四季度']\n",
    "第四季度 = list(第四季度)\n",
    "第四季度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[13360, 20630, 22663, 19366, 16490]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "第五季度 = 居民人均可支配收入累计值['2022年第一季度']\n",
    "第五季度 = list(第五季度)\n",
    "第五季度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "colors = Spectral5\n",
    "years=[\"第一季度\",\"第二季度\",\"第三季度\",\"第四季度\",\"第五季度\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "data={\n",
    "    'region':region,\n",
    "    '第一季度':第一季度,\n",
    "    '第二季度':第二季度,\n",
    "    '第三季度':第三季度,\n",
    "    '第四季度':第四季度,\n",
    "    '第五季度':第五季度\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"978a595f-866f-444d-9040-728e54bec192\" data-root-id=\"1830\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"c13d4ded-04af-4a72-bd6f-2b69b38cf778\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1841\"}],\"center\":[{\"id\":\"1843\"},{\"id\":\"1847\"},{\"id\":\"1887\"}],\"left\":[{\"id\":\"1844\"}],\"plot_height\":300,\"renderers\":[{\"id\":\"1877\"},{\"id\":\"1892\"},{\"id\":\"1906\"},{\"id\":\"1920\"},{\"id\":\"1934\"}],\"title\":{\"id\":\"1831\"},\"toolbar\":{\"id\":\"1856\"},\"x_range\":{\"id\":\"1833\"},\"x_scale\":{\"id\":\"1837\"},\"y_range\":{\"id\":\"1835\"},\"y_scale\":{\"id\":\"1839\"}},\"id\":\"1830\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"data_source\":{\"id\":\"1829\"},\"glyph\":{\"id\":\"1890\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"1891\"},\"selection_glyph\":null,\"view\":{\"id\":\"1893\"}},\"id\":\"1892\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1842\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1841\"},\"ticker\":null},\"id\":\"1843\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"1829\"}},\"id\":\"1893\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"1829\"},\"glyph\":{\"id\":\"1904\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"1905\"},\"selection_glyph\":null,\"view\":{\"id\":\"1907\"}},\"id\":\"1906\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"formatter\":{\"id\":\"1880\"},\"ticker\":{\"id\":\"1845\"}},\"id\":\"1844\",\"type\":\"LinearAxis\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1864\"}},\"fill_color\":{\"value\":\"#2b83ba\"},\"line_color\":{\"value\":\"#2b83ba\"},\"top\":{\"expr\":{\"id\":\"1865\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1875\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"1829\"}},\"id\":\"1935\",\"type\":\"CDSView\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"\\u7b2c\\u56db\\u5b63\\u5ea6\",\"\\u7b2c\\u4e94\\u5b63\\u5ea6\"]},\"id\":\"1873\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1866\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#abdda4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#abdda4\"},\"top\":{\"expr\":{\"id\":\"1867\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1891\",\"type\":\"VBar\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1864\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#2b83ba\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#2b83ba\"},\"top\":{\"expr\":{\"id\":\"1865\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1876\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1852\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1882\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\"]},\"id\":\"1867\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"1845\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1844\"},\"dimension\":1,\"ticker\":null},\"id\":\"1847\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"@years\",\"@region:@$name\"]]},\"id\":\"1855\",\"type\":\"HoverTool\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1872\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#d7191c\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#d7191c\"},\"top\":{\"expr\":{\"id\":\"1873\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1933\",\"type\":\"VBar\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1848\"},{\"id\":\"1849\"},{\"id\":\"1850\"},{\"id\":\"1851\"},{\"id\":\"1852\"},{\"id\":\"1853\"},{\"id\":\"1855\"}]},\"id\":\"1856\",\"type\":\"Toolbar\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"\\u7b2c\\u56db\\u5b63\\u5ea6\"]},\"id\":\"1871\",\"type\":\"Stack\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\"]},\"id\":\"1868\",\"type\":\"Stack\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"\\u7b2c\\u56db\\u5b63\\u5ea6\"]},\"id\":\"1872\",\"type\":\"Stack\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u56db\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"1920\"}]},\"id\":\"1930\",\"type\":\"LegendItem\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e94\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"1934\"}]},\"id\":\"1944\",\"type\":\"LegendItem\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1868\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"1869\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1905\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1849\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1870\"}},\"fill_color\":{\"value\":\"#fdae61\"},\"line_color\":{\"value\":\"#fdae61\"},\"top\":{\"expr\":{\"id\":\"1871\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1918\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"1829\"}},\"id\":\"1907\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1853\",\"type\":\"HelpTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1854\"}},\"id\":\"1850\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1880\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1851\",\"type\":\"SaveTool\"},{\"attributes\":{\"source\":{\"id\":\"1829\"}},\"id\":\"1878\",\"type\":\"CDSView\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\"]},\"id\":\"1865\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1872\"}},\"fill_color\":{\"value\":\"#d7191c\"},\"line_color\":{\"value\":\"#d7191c\"},\"top\":{\"expr\":{\"id\":\"1873\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1932\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\"]},\"id\":\"1870\",\"type\":\"Stack\"},{\"attributes\":{\"formatter\":{\"id\":\"1882\"},\"ticker\":{\"id\":\"1842\"}},\"id\":\"1841\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e00\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"1877\"}]},\"id\":\"1888\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1837\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1854\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data_source\":{\"id\":\"1829\"},\"glyph\":{\"id\":\"1875\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"1876\"},\"selection_glyph\":null,\"view\":{\"id\":\"1878\"}},\"id\":\"1877\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fields\":[]},\"id\":\"1864\",\"type\":\"Stack\"},{\"attributes\":{\"data\":{\"region\":[\"\\u5e7f\\u4e1c\\u7701\",\"\\u5317\\u4eac\",\"\\u4e0a\\u6d77\\u5e02\",\"\\u6d59\\u6c5f\\u7701\",\"\\u6c5f\\u82cf\\u7701\"],\"\\u7b2c\\u4e00\\u5b63\\u5ea6\":[12636,19585,21548,18263,15500],\"\\u7b2c\\u4e09\\u5b63\\u5ea6\":[35694,56498,58907,44712,36227],\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\":[23604,38138,40357,30998,25119],\"\\u7b2c\\u4e94\\u5b63\\u5ea6\":[13360,20630,22663,19366,16490],\"\\u7b2c\\u56db\\u5b63\\u5ea6\":[44993,75002,78027,57541,47498]},\"selected\":{\"id\":\"1884\"},\"selection_policy\":{\"id\":\"1885\"}},\"id\":\"1829\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"1892\"}]},\"id\":\"1902\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1885\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"text\":\"\\u5c45\\u6c11\\u4eba\\u5747\\u53ef\\u652f\\u914d\\u6536\\u5165\\u7d2f\\u8ba1\\u503c\"},\"id\":\"1831\",\"type\":\"Title\"},{\"attributes\":{\"items\":[{\"id\":\"1888\"},{\"id\":\"1902\"},{\"id\":\"1916\"},{\"id\":\"1930\"},{\"id\":\"1944\"}]},\"id\":\"1887\",\"type\":\"Legend\"},{\"attributes\":{\"data_source\":{\"id\":\"1829\"},\"glyph\":{\"id\":\"1918\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u56db\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"1919\"},\"selection_glyph\":null,\"view\":{\"id\":\"1921\"}},\"id\":\"1920\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1868\"}},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"1869\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1904\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\"]},\"id\":\"1866\",\"type\":\"Stack\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e09\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"1906\"}]},\"id\":\"1916\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1884\",\"type\":\"Selection\"},{\"attributes\":{\"data_source\":{\"id\":\"1829\"},\"glyph\":{\"id\":\"1932\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e94\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"1933\"},\"selection_glyph\":null,\"view\":{\"id\":\"1935\"}},\"id\":\"1934\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"1829\"}},\"id\":\"1921\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1870\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#fdae61\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#fdae61\"},\"top\":{\"expr\":{\"id\":\"1871\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1919\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1839\",\"type\":\"LinearScale\"},{\"attributes\":{\"factors\":[\"\\u5e7f\\u4e1c\\u7701\",\"\\u5317\\u4eac\",\"\\u4e0a\\u6d77\\u5e02\",\"\\u6d59\\u6c5f\\u7701\",\"\\u6c5f\\u82cf\\u7701\"]},\"id\":\"1833\",\"type\":\"FactorRange\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\"]},\"id\":\"1869\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1866\"}},\"fill_color\":{\"value\":\"#abdda4\"},\"line_color\":{\"value\":\"#abdda4\"},\"top\":{\"expr\":{\"id\":\"1867\"}},\"width\":{\"value\":0.8},\"x\":{\"field\":\"region\"}},\"id\":\"1890\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1848\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1835\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"1830\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"c13d4ded-04af-4a72-bd6f-2b69b38cf778\",\"root_ids\":[\"1830\"],\"roots\":{\"1830\":\"978a595f-866f-444d-9040-728e54bec192\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1830"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "source = ColumnDataSource(\n",
    "    data = data\n",
    ")\n",
    "\n",
    "TOOLTIPS = [\n",
    "    (\"@years\",\"@region:@$name\")\n",
    "]\n",
    "\n",
    "#画布\n",
    "p = figure(\n",
    "    x_range = region,\n",
    "    plot_height = 300,\n",
    "    title = \"居民人均可支配收入累计值\",\n",
    "#     source = source,\n",
    "    tooltips = TOOLTIPS\n",
    "\n",
    ")\n",
    "\n",
    "#画图\n",
    "p.vbar_stack(\n",
    "    years,\n",
    "    x = 'region',\n",
    "    width = 0.8,\n",
    "    color = colors,\n",
    "    source = source,\n",
    "    legend = [value(x) for x in years]\n",
    "\n",
    ")\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"8904478e-77bf-4965-a5ed-ee3df575cf57\" data-root-id=\"2246\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"bfb24bc8-623a-4fbd-8b5c-715a4807b90a\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2257\"}],\"center\":[{\"id\":\"2260\"},{\"id\":\"2263\"},{\"id\":\"2303\"}],\"left\":[{\"id\":\"2261\"}],\"plot_height\":300,\"renderers\":[{\"id\":\"2293\"},{\"id\":\"2308\"},{\"id\":\"2322\"},{\"id\":\"2336\"},{\"id\":\"2350\"}],\"title\":{\"id\":\"2247\"},\"toolbar\":{\"id\":\"2272\"},\"x_range\":{\"id\":\"2249\"},\"x_scale\":{\"id\":\"2253\"},\"y_range\":{\"id\":\"2251\"},\"y_scale\":{\"id\":\"2255\"}},\"id\":\"2246\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"text\":\"\\u5c45\\u6c11\\u4eba\\u5747\\u53ef\\u652f\\u914d\\u6536\\u5165\\u7d2f\\u8ba1\\u503c\"},\"id\":\"2247\",\"type\":\"Title\"},{\"attributes\":{\"fill_color\":{\"value\":\"#d7191c\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2288\"}},\"line_color\":{\"value\":\"#d7191c\"},\"right\":{\"expr\":{\"id\":\"2289\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2348\",\"type\":\"HBar\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\"]},\"id\":\"2284\",\"type\":\"Stack\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"2264\"},{\"id\":\"2265\"},{\"id\":\"2266\"},{\"id\":\"2267\"},{\"id\":\"2268\"},{\"id\":\"2269\"},{\"id\":\"2271\"}]},\"id\":\"2272\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"value\":\"#abdda4\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2282\"}},\"line_color\":{\"value\":\"#abdda4\"},\"right\":{\"expr\":{\"id\":\"2283\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2306\",\"type\":\"HBar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#ffffbf\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2284\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#ffffbf\"},\"right\":{\"expr\":{\"id\":\"2285\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2321\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"2298\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data_source\":{\"id\":\"2245\"},\"glyph\":{\"id\":\"2334\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u56db\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2335\"},\"selection_glyph\":null,\"view\":{\"id\":\"2337\"}},\"id\":\"2336\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2265\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e00\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2293\"}]},\"id\":\"2304\",\"type\":\"LegendItem\"},{\"attributes\":{\"formatter\":{\"id\":\"2296\"},\"ticker\":{\"id\":\"2262\"}},\"id\":\"2261\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"2269\",\"type\":\"HelpTool\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\"]},\"id\":\"2283\",\"type\":\"Stack\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#d7191c\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2288\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#d7191c\"},\"right\":{\"expr\":{\"id\":\"2289\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2349\",\"type\":\"HBar\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\"]},\"id\":\"2286\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2296\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"2268\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"2300\",\"type\":\"Selection\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"\\u7b2c\\u56db\\u5b63\\u5ea6\"]},\"id\":\"2287\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2264\",\"type\":\"PanTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2270\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2301\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\"]},\"id\":\"2281\",\"type\":\"Stack\"},{\"attributes\":{\"data\":{\"region\":[\"\\u5e7f\\u4e1c\\u7701\",\"\\u5317\\u4eac\",\"\\u4e0a\\u6d77\\u5e02\",\"\\u6d59\\u6c5f\\u7701\",\"\\u6c5f\\u82cf\\u7701\"],\"\\u7b2c\\u4e00\\u5b63\\u5ea6\":[12636,19585,21548,18263,15500],\"\\u7b2c\\u4e09\\u5b63\\u5ea6\":[35694,56498,58907,44712,36227],\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\":[23604,38138,40357,30998,25119],\"\\u7b2c\\u4e94\\u5b63\\u5ea6\":[13360,20630,22663,19366,16490],\"\\u7b2c\\u56db\\u5b63\\u5ea6\":[44993,75002,78027,57541,47498]},\"selected\":{\"id\":\"2300\"},\"selection_policy\":{\"id\":\"2301\"}},\"id\":\"2245\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\"]},\"id\":\"2282\",\"type\":\"Stack\"},{\"attributes\":{\"fill_color\":{\"value\":\"#2b83ba\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2280\"}},\"line_color\":{\"value\":\"#2b83ba\"},\"right\":{\"expr\":{\"id\":\"2281\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2291\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"2249\",\"type\":\"DataRange1d\"},{\"attributes\":{\"source\":{\"id\":\"2245\"}},\"id\":\"2309\",\"type\":\"CDSView\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"\\u7b2c\\u56db\\u5b63\\u5ea6\",\"\\u7b2c\\u4e94\\u5b63\\u5ea6\"]},\"id\":\"2289\",\"type\":\"Stack\"},{\"attributes\":{\"data_source\":{\"id\":\"2245\"},\"glyph\":{\"id\":\"2291\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2292\"},\"selection_glyph\":null,\"view\":{\"id\":\"2294\"}},\"id\":\"2293\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"overlay\":{\"id\":\"2270\"}},\"id\":\"2266\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\"]},\"id\":\"2285\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2267\",\"type\":\"SaveTool\"},{\"attributes\":{\"axis\":{\"id\":\"2261\"},\"dimension\":1,\"ticker\":null},\"id\":\"2263\",\"type\":\"Grid\"},{\"attributes\":{\"items\":[{\"id\":\"2304\"},{\"id\":\"2318\"},{\"id\":\"2332\"},{\"id\":\"2346\"},{\"id\":\"2360\"}]},\"id\":\"2303\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"2253\",\"type\":\"LinearScale\"},{\"attributes\":{\"fields\":[]},\"id\":\"2280\",\"type\":\"Stack\"},{\"attributes\":{\"formatter\":{\"id\":\"2298\"},\"ticker\":{\"id\":\"2258\"}},\"id\":\"2257\",\"type\":\"LinearAxis\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e94\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2350\"}]},\"id\":\"2360\",\"type\":\"LegendItem\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e09\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2322\"}]},\"id\":\"2332\",\"type\":\"LegendItem\"},{\"attributes\":{\"source\":{\"id\":\"2245\"}},\"id\":\"2323\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_color\":{\"value\":\"#fdae61\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2286\"}},\"line_color\":{\"value\":\"#fdae61\"},\"right\":{\"expr\":{\"id\":\"2287\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2334\",\"type\":\"HBar\"},{\"attributes\":{\"data_source\":{\"id\":\"2245\"},\"glyph\":{\"id\":\"2348\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e94\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2349\"},\"selection_glyph\":null,\"view\":{\"id\":\"2351\"}},\"id\":\"2350\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#abdda4\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2282\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#abdda4\"},\"right\":{\"expr\":{\"id\":\"2283\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2307\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"2255\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#2b83ba\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2280\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#2b83ba\"},\"right\":{\"expr\":{\"id\":\"2281\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2292\",\"type\":\"HBar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#fdae61\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2286\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#fdae61\"},\"right\":{\"expr\":{\"id\":\"2287\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2335\",\"type\":\"HBar\"},{\"attributes\":{\"data_source\":{\"id\":\"2245\"},\"glyph\":{\"id\":\"2306\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2307\"},\"selection_glyph\":null,\"view\":{\"id\":\"2309\"}},\"id\":\"2308\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data_source\":{\"id\":\"2245\"},\"glyph\":{\"id\":\"2320\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"2321\"},\"selection_glyph\":null,\"view\":{\"id\":\"2323\"}},\"id\":\"2322\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"@years\",\"@region:@$name\"]]},\"id\":\"2271\",\"type\":\"HoverTool\"},{\"attributes\":{\"source\":{\"id\":\"2245\"}},\"id\":\"2351\",\"type\":\"CDSView\"},{\"attributes\":{\"factors\":[\"\\u5e7f\\u4e1c\\u7701\",\"\\u5317\\u4eac\",\"\\u4e0a\\u6d77\\u5e02\",\"\\u6d59\\u6c5f\\u7701\",\"\\u6c5f\\u82cf\\u7701\"]},\"id\":\"2251\",\"type\":\"FactorRange\"},{\"attributes\":{\"source\":{\"id\":\"2245\"}},\"id\":\"2294\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_color\":{\"value\":\"#ffffbf\"},\"height\":{\"value\":0.8},\"left\":{\"expr\":{\"id\":\"2284\"}},\"line_color\":{\"value\":\"#ffffbf\"},\"right\":{\"expr\":{\"id\":\"2285\"}},\"y\":{\"field\":\"region\"}},\"id\":\"2320\",\"type\":\"HBar\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2308\"}]},\"id\":\"2318\",\"type\":\"LegendItem\"},{\"attributes\":{\"label\":{\"value\":\"\\u7b2c\\u56db\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"2336\"}]},\"id\":\"2346\",\"type\":\"LegendItem\"},{\"attributes\":{\"axis\":{\"id\":\"2257\"},\"ticker\":null},\"id\":\"2260\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2258\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"2262\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fields\":[\"\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"\\u7b2c\\u56db\\u5b63\\u5ea6\"]},\"id\":\"2288\",\"type\":\"Stack\"},{\"attributes\":{\"source\":{\"id\":\"2245\"}},\"id\":\"2337\",\"type\":\"CDSView\"}],\"root_ids\":[\"2246\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"bfb24bc8-623a-4fbd-8b5c-715a4807b90a\",\"root_ids\":[\"2246\"],\"roots\":{\"2246\":\"8904478e-77bf-4965-a5ed-ee3df575cf57\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2246"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "source = ColumnDataSource(\n",
    "    data = data\n",
    ")\n",
    "\n",
    "TOOLTIPS = [\n",
    "    (\"@years\",\"@region:@$name\")\n",
    "]\n",
    "\n",
    "#画布\n",
    "p = figure(\n",
    "    y_range = region,\n",
    "    plot_height = 300,\n",
    "    title = \"居民人均可支配收入累计值\",\n",
    "#     source = source,\n",
    "    tooltips = TOOLTIPS\n",
    "\n",
    ")\n",
    "\n",
    "#画图\n",
    "p.hbar_stack(\n",
    "    years,\n",
    "    y = 'region',\n",
    "    height = 0.8,\n",
    "    color = colors,\n",
    "    source = source,\n",
    "    legend = [value(y) for y in years]\n",
    "\n",
    ")\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
